import Vue from 'vue'
import Vuex from 'Vuex'

Vue.use(Vuex);

function getDefaultCity(){	
	try{
		if(window.localStorage.city){
			return window.localStorage.city;
		}else{
			return "北京";
		}
	}catch(error){
		console.log("获取城市数据出错,"+error);
	}
}

//获取服务器环境变量
function getDefaultEvn(){
	if(process.env.NODE_ENV=="development"){
		return {
            server8092:"/"
		}
	}else if(process.env.NODE_ENV=="production"){
		return {
			server8092:"http://192.168.13.1:8092/"
		}
	}else if(process.env.NODE_ENV=="pre-production"){
		return {
			server8090:"172.10.168.112"
		}
	}
}

//state
var state={
	city:getDefaultCity(),
	env:getDefaultEvn()
}

//mutations
var mutations={
	setCity(state,city){
		state.city=city;
		try{
			window.localStorage.city=city;
		}catch(error){
			console.log("设置城市数据出错,"+error);
		}
	}
}

//actions
var actions={
	setCity(context,city){
		context.commit("setCity",city);
	}
}

//getters
var getters={
	city(){
		return state.city;
	},
	env(){
		return state.env;
	}
}

export default new Vuex.Store({
	"state":state,
	"actions":actions,
	"mutations":mutations,
	"getters":getters
});